package main

import (
	"fmt"
	"log"
	"os"
)

func LogExample() {
	fmt.Println("begin TestLog ...")
	file, err := os.Create("test.log")
	if err != nil {
		log.Fatalln("fail to create test.log file!")
	}
	//New创建一个Logger。参数out设置日志信息写入的目的地。参数prefix会添加到生成的每一条日志前面。参数flag定义日志的属性（时间、文件等等）。
	//log.LstdFlags:标准logger的初始值(日期+时间,示例:"2016/09/14 15:30:18")
	//log.Llognfile:文件全路径名+行号 -- 示例: /a/b/c/d.go:23
	//Lshortfile:文件无路径名+行号:  -- 示例: d.go:23（会覆盖掉Llongfile）
	logger := log.New(file, "this is test ", log.LstdFlags|log.Lshortfile)
	log.Println("1.Println log with log.LstdFlags ...")
	logger.Println("1.Println log with log.LstdFlags ...")

	//logger.SetFlags(log.LstdFlags)

	log.Println("2.Println log without log.LstdFlags ...")
	logger.Println("2.Println log without log.LstdFlags ...")

	//log.Panicln("3.std Panicln log without log.LstdFlags ...")
	//fmt.Println("3 Will this statement be execute ?")
	//logger.Panicln("3.Panicln log without log.LstdFlags ...")

	log.Println("4.Println log without log.LstdFlags ...")
	logger.Println("4.Println log without log.LstdFlags ...")

	log.Fatal("5.std Fatal log without log.LstdFlags ...")
	fmt.Println("5 Will this statement be execute ?")
	logger.Fatal("5.Fatal log without log.LstdFlags ...")
}

func main() {
	LogExample()
	fmt.Println("main over")
}
